namespace SimpleWebServices.Configuration
{
    using System.Configuration;
    using System.Xml;
    using Xunit;

    public sealed class DataConfigurationFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<DataConfiguration>()
                .DerivesFrom<object>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Implements<IConfigurationSectionHandler>()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new DataConfiguration());
        }

        [Fact]
        public void op_Settings()
        {
            Assert.NotNull(DataConfiguration.Settings());
        }

        [Fact]
        public void op_Settings_string()
        {
            Assert.NotNull(DataConfiguration.Settings("simplewebservices/data"));
        }

        [Fact]
        public void op_Create_object_object_XmlNodeNull()
        {
            DataSettings actual = new DataConfiguration().Create(null, null, null as XmlNode) as DataSettings;

            Assert.NotNull(actual);
        }

        [Fact]
        public void op_Create_object_object_XmlNodeEmpty()
        {
            XmlDocument xml = new XmlDocument();
            xml.LoadXml("<data />");

            DataSettings actual = new DataConfiguration().Create(null, null, xml.DocumentElement) as DataSettings;

            Assert.NotNull(actual);
        }

        [Fact]
        public void op_Create_object_object_XmlNode()
        {
            XmlDocument xml = new XmlDocument();
            xml.LoadXml(
                "<data enabled='true'>" +
                    "<xml path='~Data.object.xml' />" +
                "</data>");

            DataSettings actual = new DataConfiguration().Create(null, null, xml.DocumentElement) as DataSettings;

            Assert.Equal<int>(1, actual.XmlDataSettings.Count);
        }

        [Fact]
        public void op_Create_object_object_XmlNodeInvalid()
        {
            XmlDocument xml = new XmlDocument();
            xml.LoadXml("<bad-name/>");

            Assert.Throws<ConfigurationErrorsException>(() => new DataConfiguration().Create(null, null, xml.DocumentElement));
        }
    }
}